package cc.mrbird.system.controller;

import cc.mrbird.common.annotation.Log;
import cc.mrbird.common.controller.BaseController;
import cc.mrbird.common.domain.QueryRequest;
import cc.mrbird.common.domain.ResponseBo;
import cc.mrbird.system.domain.*;
import cc.mrbird.system.service.DaliyService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.util.List;

/**
 * 日报的信息
 */
@Controller
public class DaliyController extends BaseController {
    @Autowired
    private DaliyService daliyService;

    //日志
    private Logger log = LoggerFactory.getLogger(this.getClass());


    @Log("获取角色信息")
    @RequestMapping("daily")
    //后期可能会改 误删
    //@RequiresPermissions("daily:information")
    public String index() {
        return "system/daily/daily";
    }


    /**
     * 获取用户信息以及未签到的天数
     * @return
     */
    @RequestMapping("daily/information")
    //@RequiresPermissions("daily:information")
    @ResponseBody
    public ResponseBo daliyInformation() throws ParseException {
        try {
            DaliyDTO daliyMessage = daliyService.daliyMessage();
            return ResponseBo.ok(daliyMessage);
        } catch (Exception e) {
            log.error("获取日报信息", e);
            return ResponseBo.error("获取日报信息失败，请联系网站管理员！");
        }

    }

    /**
     * 新增日报
     * @param daily 添加的日报 数组
     * @param executioneFficiency 效率
     * @param reasonsforeFficiencyFailure 效率不及格原因
     */
    @RequestMapping("daily/present")
    @ResponseBody
    public ResponseBo present(String daily,String executioneFficiency,String reasonsforeFficiencyFailure) throws ParseException {
        try {
            //日报信息
            List<DaliyDTO> daliyList = JSONObject.parseArray(daily, DaliyDTO.class);
            //添加日报
            Boolean states =  daliyService.adliyAdd(daliyList,executioneFficiency,reasonsforeFficiencyFailure);
            return ResponseBo.ok(states == true ? "添加成功！": "添加失败");
        } catch (Exception e) {
            log.error("获取日报信息", e);
            return ResponseBo.error("获取日报信息失败，请联系网站管理员！");
        }

    }




}
